<template>
	<view>
		<view style="display: flex;">
			<text>姓名：</text><input v-model="newobj.name" style="width: 80%;" placeholder="请输入姓名"/>
		</view>
		<view style="display: flex;">
			<text>性别：</text>	<radio-group @change="(e)=>{
				console.log(1111)
				newobj.sex=e.detail.value
			}">
				<label class="radio"><radio :checked="'男'===newobj.sex" value="男"/>男</label>
				<label class="radio"><radio :checked="'女'===newobj.sex" value="女"/>女</label>
			</radio-group>
		</view>
		<view style="display: flex;">
			<text>生日：</text><input v-model="newobj.birthday" @focus="show=true" style="width: 80%;" placeholder="请选择生日"/>
		</view>
		<view style="display: flex;">
			<text>手机号：</text><input v-model="newobj.phone" style="width: 80%;" placeholder="请输入手机号"/>
		</view>
		   <view>
		        <up-datetime-picker
		        
		            :show="show"
		           @confirm="(e)=>{
					  let time=new Date(e.value).toLocaleDateString()
					  newobj.birthday=time.replace('/','-')
					  newobj.birthday=  newobj.birthday.replace('/','-')
						  show=false
				   }"
				   @cancel="show=false"
		            mode="date"
		        ></up-datetime-picker>
		    </view>
			<button @click="add">
				添加
			</button>
	</view>

</template>

<script lang="ts" setup>
	import {onMounted, ref} from 'vue'
		import request from "../../components/promise/promise";
	let newobj=ref({
		name:'', 
		birthday:'',
		phone:''
	})

	const show = ref(false);
	let add=async()=>{
		console.log(newobj)
		await request({url:'http://47.93.162.7:3000/adduserlist',method:"POST",data:{user:newobj}})
	
		  uni.navigateBack({
		    delta: 1 // 返回的页面层数，1 表示返回上一层页面
		  });
		  
		  // 销毁当前页面
		  uni.redirectTo({
		    url: '/pages/index/addpeople' // 当前页面的路径
		  });
		}

	

</script>

<style>
</style>